from owtf.dependency_management.dependency_resolver import ServiceLocator


DESCRIPTION = "Launches all Exploits for a category(ies) -i.e. for IDS testing-"
CATEGORIES = ['LINUX', 'WINDOWS', 'OSX']
SUBCATEGORIES = ['DCERPC', 'FTP', 'HTTP', 'IIS', 'IMAP', 'ISAPI', 'LDAP', 'LPD', 'MDNS', 'MISC', 'MMSP', 'MSSQL',
                 'MYSQL', 'NOVELL', 'NFS', 'NNTP', 'NTP', 'ORACLE', 'PHP', 'POP3', 'POSTGRES', 'PPTP', 'PROXY',
                 'REALSERVER', 'RPC', 'RTSP', 'SAMBA', 'SCADA', 'SIP', 'SMB', 'SMTP', 'SOFTCART', 'SSH', 'SSL',
                 'SUNRPC', 'SVN', 'TACACS', 'TELNET', 'TFTP', 'UNICENTER', 'VNC', 'VPN', 'WEBAPP', 'WINS', 'WYSE']


def run(PluginInfo):
    Content = []
    plugin_params = ServiceLocator.get_component("plugin_params")
    config = ServiceLocator.get_component("config")
    args = {
        'Description': DESCRIPTION,
        'Mandatory': {
            'RHOST': config.get_val('RHOST_DESCRIP'),
            'RPORT': config.get_val('RPORT_DESCRIP'),
            'CATEGORY': 'Category to use (i.e. ' + ', '.join(sorted(CATEGORIES)) + ')',
            'SUBCATEGORY': 'Subcategory to use (i.e. ' + ', '.join(sorted(SUBCATEGORIES)) + ')'
        },
        'Optional': {'REPEAT_DELIM': config.get_val('REPEAT_DELIM_DESCRIP')}
    }
    for Args in plugin_params.get_args(args, PluginInfo):
        plugin_params.set_config(Args)
        resource = config.get_resources('LaunchExploit_' + Args['CATEGORY'] + "_" + Args['SUBCATEGORY'])
        Content += ServiceLocator.get_component("plugin_helper").CommandDump('Test Command', 'Output',
                                                                             resource, PluginInfo, "")
    return Content
